﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class District
    {
        private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public District()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int Id { get; set; }
        public int ProvinceId { get; set; }
        public string DistrictDisplay { get; set; }
        public string DistrictName { get; set; }

        public int Insert(District obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO District(ProvinceId,DistrictDisplay,DistrictName) values( N'{0}', N'{1}', N'{2}')"
                                       , obj.ProvinceId, obj.DistrictDisplay, obj.DistrictName);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(District obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE District SET ProvinceId='{0}', DistrictDisplay=N'{1}', DistrictName=N'{2}' WHeRE Id= N'{3}'"
                                       , obj.ProvinceId, obj.DistrictDisplay, obj.DistrictName, obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Delete(District obj)
        {
            int result = 0;
            string sql = string.Format("DELETE District Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}